package com.study.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @author study
 * @version 1.0
 * @date 2020/9/26 18:05
 */
public class WebSocketNettyServer {
    public static void main(String[] args) {
        NioEventLoopGroup maiGrp = new NioEventLoopGroup();//主线程池
        NioEventLoopGroup subGrop = new NioEventLoopGroup();//从线程池

        try {
            //netty服务器启动对象
            ServerBootstrap bootstrap = new ServerBootstrap();

            //初始化服务器启动对象
            bootstrap.group(maiGrp, subGrop)//
                    .channel(NioServerSocketChannel.class)//
                    .childHandler(new WebSocketChannelInitializer());

            ChannelFuture future = bootstrap.bind(9090).sync();

            //等待关闭服务
            future.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            maiGrp.shutdownGracefully();
            subGrop.shutdownGracefully();
        }

    }
}
